#include<bits/stdc++.h>
using namespace std;
int n,cnt,t,b[100005],color[100],num[100];
struct node
{
  int place,color;
}a[100005],c[100005];
int main()
{
        freopen("color.in","r",stdin);
        freopen("color.out","w",stdout);
        cin>>t;
        for(int j=1;j<=t;j++)
        {
          cin>>n;
          cnt=0;
          num[0]=num[1]=0;
          color[0]=color[1]=0;
          for(int i=1;i<=n;i++)
          {
             cin>>b[i];
             if(a[b[i]].place==0)
             {
               if(num[0]>num[1])
               {
                 a[b[i]].color=1;
                 num[1]=1;
                 color[1]=i;
                 c[i].color=1;
               }
               else if(num[0]<=num[1])
               {
                 a[b[i]].color=0;
                 num[0]=1;
                 color[0]=i;
               }
               a[b[i]].place=i;
             }
             else
             {
                if(a[b[i]].place==color[a[b[i]].color]&&a[b[i]].place!=0)
                {
                   cnt+=b[i];
                   a[b[i]].place=color[a[b[i]].color]=i;
                   num[a[b[i]].color]--;
                }
                else
                {
                   if(num[0]>num[1])
                   {
                     a[b[i]].color=1;
                     num[1]=1;
                     color[1]=i;
                   }
                   else if(num[0]<=num[1])
                   {
                     a[b[i]].color=0;
                     num[0]=1;
                     color[0]=i;
                   }
                   a[b[i]].place=i;
                }
             
          }
        }
        cout<<cnt<<endl;
        }
        return 0;
	
	   
}
